//
//  SNSettingViewController.m
//  project
//
//  Created by 黄建华 on 2017/11/20.
//  Copyright © 2017年 黄建华. All rights reserved.
//

#import "SNSettingViewController.h"
#import "SNInfoView.h"
#import "SNPersonSetViewController.h"
#import  "FeedBackViewController.h"
#import "AppleHealthyViewController.h"
#import "project-Swift.h"
#import "SNFriendVc.h"
#import "SNSettingInfoCell.h"
#import "AssociatedTmallGenieViewController.h"

@interface SNSettingViewController ()<UITableViewDelegate, UITableViewDataSource, UIAlertViewDelegate>
@property(nonatomic, strong) UIImageView  *backImageView;
@property(nonatomic, strong) UIView       *backView;
@property(nonatomic, strong) SNInfoView   *firstView;
@property(nonatomic, strong) SNInfoView   *secondView;
@property(nonatomic, strong) SNInfoView   *thirdView;
@property(nonatomic, strong) SNInfoView   *forthView;
@property(nonatomic, strong) UITableView  *tableView;
@property(nonatomic, strong) NSMutableArray *dataSource;
@property(nonatomic, strong) UIButton     *headImageBtn;
@property(nonatomic, strong) UILabel      *nameLabel;
@property(nonatomic, strong) UILabel      *weightLabel;
@property(nonatomic, strong) UILabel      *dateLabel;
@property(nonatomic, strong) UILabel      *BMILabel;
@property(nonatomic, strong) UILabel      *userIDLabel;
@property(nonatomic, assign) BOOL         selected;
@property (nonatomic, strong) UIImageView *animateView;
@property (nonatomic, strong) UIView      *bgView;
@end

@implementation SNSettingViewController

- (void)SNBecomeActive
{
    if (ISOPENFRIENDFUNCTION) {
        if ([HASLOGIN getBOOLValue] == YES) {
            DEF_WEAKSELF_(SNSettingViewController)
            [SN_Net friendSystemNoReadSuccess:^(id object) {
                [weakSelf.tableView reloadData];
            } fail:^(id object) {
                
            }];
        }
    }
}

- (void)SNBebackground
{
  
}

- (void)OTACANINFONOTICE2
{
    NSLog(@"🙂4444 otaUpdateInfoView");
    [self otaUpdateInfoView];
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    
    if ([FileModelEntity sharedInstance].otacanInfo) {
          NSLog(@"🙂直接弹OTA 11111");
          [self otaUpdateInfoView];
      }
      else
      {
          NSLog(@"🙂等待直接弹OTA 22222");
      }
      
      [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(OTACANINFONOTICE2) name:OTACANINFONOTICE object:nil];
    
    if (SN_USER.portrait.length > 0) {
        _headImageBtn.image = SN_USER.headImage;
    } else {
        _headImageBtn.image = [UIImage imageNamed:@"loginhead"];
    }
    _nameLabel.text   = SN_USER.nickName;
    _weightLabel.text = SN_USER.weightunitSet ? [NSString stringWithFormat:@"%.1flb", SN_USER.weight*2.2] : [NSString stringWithFormat:@"%.1fkg",1.0 * SN_USER.weight];
    if ([SN_USER.weightTime isEqualToString:@"0000-00-00"]) {
        _dateLabel.text = SN_Text(@"暂无数据");
    } else {
        _dateLabel.text = [NSString stringWithFormat:@"%@", SN_USER.weightTime];
    }
    _BMILabel.text = [NSString stringWithFormat:@"%@", SN_USER.BMI];
    [SportModel getMaxDayStep];
    [SportModel getmaxContinueDays];
    [SportModel getMaxWeekStep];
    [SportModel getMaxMonthStep];
    [self updateUI];
    
    if (ISOPENFRIENDFUNCTION) {
        DEF_WEAKSELF_(SNSettingViewController)
        [SN_Net friendSystemNoReadSuccess:^(id object) {
            [weakSelf.tableView reloadData];
        } fail:^(id object) {
            
        }];
    }
    
    if (!IOSSHOWTARBARACTIVE) {
        return;
    }
    NSInteger width = 0;
    if (KK_ShareData.lastVcTag > KK_ShareData.currentVCTag) {
        width = HHHWIDTH;
    }
    if (KK_ShareData.lastVcTag < KK_ShareData.currentVCTag) {
        width = -HHHWIDTH;
    }
    
    if (KK_ShareData.lastVcTag == KK_ShareData.currentVCTag) {
        width = 0;
    }
    if (width != 0) {
        if (_bgView) {
            [_bgView removeFromSuperview];
            _bgView = nil;
        }
        if (_animateView) {
            [_animateView removeFromSuperview];
            _animateView = nil;
        }
        
        _animateView = [[UIImageView alloc]initWithFrame:self.view.frame];
        [self.view addSubview:_animateView];
        UIGraphicsBeginImageContextWithOptions(CGSizeMake(HHHWIDTH, HHHHEIGHT), NO, 0.0);
        [self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
        UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();
        _animateView.image = viewImage;
        
        _bgView                 = [[UIView alloc] initWithFrame:self.view.frame];
        _bgView.backgroundColor = self.view.backgroundColor;
        [self.view addSubview:_bgView];
        [self.view bringSubviewToFront:_animateView];
        _animateView.frame  = SNFRAME(width, 0, HHHWIDTH, HHHHEIGHT);
        _animateView.hidden = NO;
        _bgView.hidden      = NO;
        [UIView animateWithDuration:VIEWANIMATETIME animations:^{
            _animateView.frame = SNFRAME(0, 0, HHHWIDTH, HHHHEIGHT);
        } completion:^(BOOL finished) {
            _animateView.hidden = YES;
            _bgView.hidden = YES;
        }];
    }
}

- (void)updateUI {
    _firstView.contentStr = [NSString stringWithFormat:@"%ld %@", (long)SN_USER.max_step, SN_Text(@"步")];
    _firstView.dateStr    = SN_USER.max_step_date;
    
    _secondView.contentStr = [NSString stringWithFormat:@"%ld %@", (long)SN_USER.max_reach_times, SN_Text(@"天")];
    if (SN_USER.max_reach_times > 0) {
        _secondView.dateStr = [NSString stringWithFormat:@"%@～%@", [SN_USER.max_reach_start substringFromIndex:5], [SN_USER.max_reach_end substringFromIndex:5]];
    }
    
    _thirdView.contentStr = [NSString stringWithFormat:@"%ld %@", (long)SN_USER.max_week_step, SN_Text(@"步")];
    if (SN_USER.max_week_step > 0) {
        _thirdView.dateStr = [NSString stringWithFormat:@"%@～%@", [SN_USER.max_week_start substringFromIndex:5], [SN_USER.max_week_end substringFromIndex:5]];
    }
    
    _forthView.contentStr = [NSString stringWithFormat:@"%ld %@", (long)SN_USER.max_month_step, SN_Text(@"步")];
    if (SN_USER.max_month_step > 0) {
        _forthView.dateStr = [NSString stringWithFormat:@"%@", SN_USER.max_month];
    }
}

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
//    _backImageView.hidden = YES;
//    _tableView.hidden = YES
    
    [[NSNotificationCenter defaultCenter]removeObserver:self name:OTACANINFONOTICE object:nil];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self addHeadView];
    [self addInfoView];
    [self addTableView];
}

- (void)addHeadView {
    UIImage *backImage = UIImageNamed(@"背景");
    
    _backImageView                        = [[UIImageView alloc]initWithFrame:CGRectMake(0, 20+FitSimpleIpx(0, 20), HHHWIDTH, HHHWIDTH*backImage.size.height/backImage.size.width)];
    _backImageView.userInteractionEnabled = YES;
    _backImageView.image                  = backImage;
    [self.view addSubview:_backImageView];
    
    UIButton *shareBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    shareBtn.image = UIImageNamed(@"分享");
    shareBtn.frame = CGRectMake(HHHWIDTH -44 -10, 20+FitSimpleIpx(0, 20), 40, 40);
    [shareBtn addTouchUpTarget:self action:@selector(shareBtnClick)];
    [self.view addSubview:shareBtn];
    
    _headImageBtn                    = [UIButton buttonWithType:UIButtonTypeCustom];
    _headImageBtn.frame              = CGRectMake(HHHWIDTH/12, HHHWIDTH/5, HHHWIDTH/3, HHHWIDTH/3);
    _headImageBtn.layer.cornerRadius = HHHWIDTH/6;
    _headImageBtn.clipsToBounds      = YES;
    _headImageBtn.layer.borderColor  = SNCOLORWHITE.CGColor;
    _headImageBtn.layer.borderWidth  = 1;
    [self.view addSubview:_headImageBtn];
    
    CGFloat labelHeight = (_headImageBtn.width-FitH(20))/5;
    CGFloat width       = FitSimpleSize(-22, -22, 0, 0, 0);
    CGFloat font        = FitSimpleSize(10.0, 11.0, 13.0, 13.0, 13.0);
    _nameLabel           = [[UILabel alloc]initWithFrame:CGRectMake(HHHWIDTH/2 +width, HHHWIDTH/5, HHHWIDTH/2, labelHeight)];
    _nameLabel.textColor = SNCOLORWHITE;
    _nameLabel.font      = SNFONTMIN(14);
    [self.view addSubview:_nameLabel];
    
    NSArray *arr = @[@"ID：", @"上次测量体重：", @"上次测量日期：", @"BMI指数："];
    for (int i = 0; i < 4; i++) {
        UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(HHHWIDTH/2 +width -10, _nameLabel.bottom+FitH(5)+(FitH(5)+labelHeight)*i, HHHWIDTH/2, labelHeight)];
        label.text          = SN_Text(arr[i]);
        label.textColor     = UIColorHEX(0x838485);
        label.font          = SNFONTMIN(font);
        label.textAlignment = NSTextAlignmentLeft;
        CGSize titleSize = [label.text sizeWithFont:label.font maxSize:CGSizeMake(MAXFLOAT, labelHeight)];
        label.size = CGSizeMake(titleSize.width, labelHeight);
        [self.view addSubview:label];
        label.adjustsFontSizeToFitWidth = YES;
        if (i == 0) {
            _userIDLabel           = [[UILabel alloc]initWithFrame:CGRectMake(label.right, _nameLabel.bottom+FitH(5), HHHWIDTH-label.right, labelHeight)];
            _userIDLabel.textColor = SNCOLORWHITE;
            _userIDLabel.font      = SNFONTMIN(font);
            _userIDLabel.text      = [NSString stringWithFormat:@"%@", SN_USER.user_id];
            [self.view addSubview:_userIDLabel];
            _userIDLabel.adjustsFontSizeToFitWidth = YES;
        } else if (i == 1) {
            _weightLabel           = [[UILabel alloc]initWithFrame:CGRectMake(label.right, _userIDLabel.bottom+FitH(5), HHHWIDTH-label.right, labelHeight)];
            _weightLabel.textColor = SNCOLORWHITE;
            _weightLabel.font      = SNFONTMIN(font);
            [self.view addSubview:_weightLabel];
            _weightLabel.adjustsFontSizeToFitWidth = YES;
        } else if (i == 2) {
            _dateLabel           = [[UILabel alloc]initWithFrame:CGRectMake(label.right, _weightLabel.bottom+FitH(5), HHHWIDTH-label.right, labelHeight)];
            _dateLabel.textColor = SNCOLORWHITE;
            _dateLabel.font      = SNFONTMIN(font);
            [self.view addSubview:_dateLabel];
            _dateLabel.adjustsFontSizeToFitWidth = YES;
        } else {
            _BMILabel           = [[UILabel alloc]initWithFrame:CGRectMake(label.right, _dateLabel.bottom+FitH(5), HHHWIDTH-label.right, labelHeight)];
            _BMILabel.textColor = SNCOLORWHITE;
            _BMILabel.font      = SNFONTMIN(font);
            [self.view addSubview:_BMILabel];
            _BMILabel.adjustsFontSizeToFitWidth = YES;
        }
    }
}

- (void)addInfoView {
    _backView = [[UIView alloc]initWithFrame:CGRectMake(0, _backImageView.bottom, HHHWIDTH, FitH(260))];
    
    _firstView = [[SNInfoView alloc]initWithFrame:CGRectMake(FitW(25), FitH(30), HHHWIDTH/2-FitW(25), FitH(120)) withType:0];
    
    [_backView addSubview:_firstView];
    
    _secondView = [[SNInfoView alloc]initWithFrame:CGRectMake(HHHWIDTH/2+FitW(25), FitH(30), HHHWIDTH/2-FitW(25), FitH(120)) withType:1];
    
    [_backView addSubview:_secondView];
    
    _thirdView = [[SNInfoView alloc]initWithFrame:CGRectMake(FitW(25), _firstView.bottom, HHHWIDTH/2-FitW(25), FitH(120)) withType:2];
    
    [_backView addSubview:_thirdView];
    
    _forthView = [[SNInfoView alloc]initWithFrame:CGRectMake(HHHWIDTH/2+FitW(25), _firstView.bottom, HHHWIDTH/2-FitW(25), FitH(120)) withType:3];
    
    [_backView addSubview:_forthView];
    [self updateUI];
//    UILabel *line = [[UILabel alloc]initWithFrame:CGRectMake(0, _backView.bottom-1, HHHWIDTH, 1)];
//    line.backgroundColor = SNCOLORSEPRATE;
//    [_backView addSubview:line];
    
}

- (void)addTableView {
    _dataSource = [NSMutableArray array];
    [_dataSource addObject:@""];
     if (ISOPENFRIENDFUNCTION) {
        [_dataSource addObject:SN_Text(@"我的好友")];
     }
    [_dataSource addObject:SN_Text(@"个人设置1")];
    [_dataSource addObject:SN_Text(@"连接")];
//    [_dataSource addObject:SN_Text(@"苹果健康")];
    [_dataSource addObject:@"Strava"];
    
    NSLog(@"[NSObject getCurrentLanguage]:%@",[NSObject getCurrentLanguage]);
    
    if ([[NSObject getCurrentLanguage] isEqualToString:@"zh-Hans-CN"]) {
        if (SN_USER.isSupportTianMao == YES) {
            [_dataSource addObject:SN_Text(@"关联天猫精灵")];
        }
    }
//    [_dataSource addObject:SN_Text(@"微信运动")];
    [_dataSource addObject:SN_Text(@"帮助与反馈")];
    [_dataSource addObject:SN_Text(@"意见反馈1")];
//    [_dataSource addObject:SN_Text(@"帮助")];
    [_dataSource addObject:SN_Text(@"退出当前登录账号")];
    
    _tableView                              = [[UITableView alloc]initWithFrame:CGRectMake(0, _backImageView.bottom, HHHWIDTH, HHHHEIGHT-_backImageView.bottom-49) style:UITableViewStylePlain];
    _tableView.delegate                     = self;
    _tableView.dataSource                   = self;
    _tableView.separatorStyle               = UITableViewCellSeparatorStyleNone;
    _tableView.tableHeaderView              = _backView;
    _tableView.showsVerticalScrollIndicator = NO;
    [self.view addSubview:_tableView];
    
    _tableView.backgroundColor = [UIColor clearColor];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return _dataSource.count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.row == 0) {
        return 0;
    }
    else
    return 50;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *identifier = @"SNSettingInfoCell";
    SNSettingInfoCell  *cell       = [tableView cellForRowAtIndexPath:indexPath];
    
    if (nil == cell) {
        cell = [[SNSettingInfoCell alloc] initWithStyle:(UITableViewCellStyleDefault) reuseIdentifier:identifier];
    }
    NSString *title = [_dataSource objectAtIndex:indexPath.row];
    [cell updateCellWithModel:title withHeight:50];
    if ([title isEqualToString:SN_Text(@"连接")] || [title isEqualToString:SN_Text(@"帮助与反馈")]||[title isEqualToString:SN_Text(@"退出当前登录账号")]) {
    UIView *tempView1 = [[UIView alloc] initWithFrame:cell.frame];
    tempView1.backgroundColor   = [UIColor clearColor];
    cell.selectedBackgroundView = tempView1;
    }
    if ([title isEqualToString:SN_Text(@"退出当前登录账号")]) {
        [cell.loginOutButton addTarget:self action:@selector(loginOutClick) forControlEvents:UIControlEventTouchUpInside];
    }
    return cell;
}

//- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
//    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
//    if (!cell) {
//        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
//            UILabel *titleLabel = [[UILabel alloc] init];
//            [cell addSubview:titleLabel];
//            titleLabel.tag = indexPath.row*100;
//            
//            UIImageView *imageView = [[UIImageView alloc] init];
//            [cell addSubview:imageView];
//            imageView.tag = indexPath.row *1000;
//        
//            UIButton *button = [[UIButton alloc] init];
//            [cell addSubview:button];
//            button.tag = 10000;
//        
//            UIButton *redButton = [[UIButton alloc] init];
//            [cell addSubview:redButton];
//            redButton.tag = 3333;
//    }
//    cell.textLabel.textColor = SNCOLORGRAY;
//    cell.textLabel.font = SNFONT(16.0);
//    NSString *title = _dataSource[indexPath.row];
//    
//    UIImageView *imageV = (UIImageView *)[cell viewWithTag:indexPath.row *1000];
//    imageV.frame = SNFRAME(20, 7.5, 35, 35);
//    
//    UILabel *labelL = (UILabel *)[cell viewWithTag:indexPath.row *100];
//    labelL.frame = SNFRAME(imageV.right + 15, 14, 200, 20);
//    labelL.font = SNFONT(17.0);
//    labelL.textAlignment = NSTextAlignmentLeft;
//    
//    UIButton *redButton = (UIButton *)[cell viewWithTag:3333];
//    redButton.backgroundColor = [UIColor redColor];
////    redButton.frame = 
//    
//    if ([title isEqualToString:SN_Text(@"连接")]) {
//        cell.textLabel.text = title;
//    }
//    if ([title isEqualToString:SN_Text(@"帮助与反馈")]) {
//        cell.textLabel.text = title;
//    }
//    
//    if ([title isEqualToString:SN_Text(@"我的好友")]) {
//        labelL.text = title;
//        imageV.image = [UIImage imageNamed:@"好友"];
//        float width = [self getWidthWithText:SN_Text(@"我的好友") height:20 font:17.0] +10;
//        redButton.frame = SNFRAME(labelL.left +width, cell.textLabel.top + 6, 8, 8);
//        redButton.layer.masksToBounds = YES;
//        redButton.layer.cornerRadius = 4;
//        if (SN_PublicClass.isFriendNewMessage) {
//            redButton.hidden = NO;
//        }
//        else
//        {
//            redButton.hidden = YES;
//        }
//    }
//    
//    if ([title isEqualToString:SN_Text(@"个人设置1")]) {
//        imageV.image = [UIImage imageNamed:@"个人设置"];
//        labelL.text = title;
//    }
//
//    if ([title isEqualToString:SN_Text(@"Strava")]) {
//        imageV.image = [UIImage imageNamed:@"Strava"];
//        if (SN_PublicClass.showStravaToken) {
//            labelL.text = [NSString stringWithFormat:@"%@ (%@)",SN_Text(@"Strava"),SN_Text(@"已授权")];
//        }
//        else
//        {
//            labelL.text = [NSString stringWithFormat:@"%@ (%@)",SN_Text(@"Strava"),SN_Text(@"未授权")];
//        }
//        
//        UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 30, 30)];
//        [imageView setImage:UIImageNamed(@"进入(1)")];
//        cell.accessoryView = imageView;
//    }
//    if ([title isEqualToString:SN_Text(@"微信运动")]) {
//        imageV.image = [UIImage imageNamed:@"微信运动"];
//        labelL.text = title;
//    }
//    if ([title isEqualToString:SN_Text(@"苹果健康")]) {
//        imageV.image = [UIImage imageNamed:@"GoogleFit"];
//        labelL.text = title;
//        
//        UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 30, 30)];
//        [imageView setImage:UIImageNamed(@"进入(1)")];
//        cell.accessoryView = imageView;
//    }
//
//    if ([title isEqualToString:SN_Text(@"意见反馈1")]) {
//        imageV.image = [UIImage imageNamed:@"意见反馈"];
//         labelL.text = title;
//        
//        UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 30, 30)];
//        [imageView setImage:UIImageNamed(@"进入(1)")];
//        cell.accessoryView = imageView;
//    }
//    if ([title isEqualToString:SN_Text(@"帮助")]) {
//          imageV.image = [UIImage imageNamed:@"帮助"];
//          labelL.text = title;
//        
//    }
//    if ([title isEqualToString:SN_Text(@"退出当前登录账号")]) {
//        UIButton *button = (UIButton *)[cell viewWithTag:10000];
//        button.frame = SNFRAME(20,5, HHHWIDTH -40, 40);
//        button.backgroundColor = SNCOLORBLACK;
//        button.layer.cornerRadius = 4.0;
//        [button setTitle:title forState:UIControlStateNormal];
//        [button setTitleColor:SNCOLORWHITE forState:UIControlStateNormal];
//        [button setTitleColor:SNCOLORGRAYLINE forState:UIControlStateHighlighted];
//        [button addTarget:self action:@selector(loginOutClick) forControlEvents:UIControlEventTouchUpInside];
//    }
//    return cell;
//}

- (CGFloat)getWidthWithText:(NSString *)text height:(CGFloat)height font:(CGFloat)font {
    CGRect rect = [text boundingRectWithSize:CGSizeMake(MAXFLOAT, height)
                                     options:NSStringDrawingUsesLineFragmentOrigin
                                  attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:font]}
                                     context:nil];
    
    return rect.size.width;
}

- (void)loginOutClick
{
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:SN_Text(@"是否确定？")
                                                    message:SN_Text(@"退出当前账户/游客登录模式后，您的设备蓝牙将断开，是否要继续") delegate:self
                                          cancelButtonTitle:nil
                                          otherButtonTitles:SN_Text(@"取消"), SN_Text(@"确定"), nil];
    [[UIView appearance] setTintColor:UIColorRGB(72, 72, 72)];
    [alert show];
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    if (self.selected == NO) {
        self.selected = YES;
        NSString *title = _dataSource[indexPath.row];
        if ([title isEqualToString:SN_Text(@"我的好友")])
        {
            SNFriendVc *fr = [[SNFriendVc alloc] init];
            CustomTabBar *tabBar = (CustomTabBar *)self.tabBarController;
            [tabBar hiddenTheTabBarView];
            [self.navigationController pushViewController:fr animated:YES];
        }
        if ([title isEqualToString:SN_Text(@"个人设置1")])
        {
            SNPersonSetViewController *personVC = [[SNPersonSetViewController alloc]init];
            personVC.type = 1;
            CustomTabBar *tabBar = (CustomTabBar *)self.tabBarController;
            [tabBar hiddenTheTabBarView];
            [self.navigationController pushViewController:personVC animated:YES];
        }
        if ([title isEqualToString:SN_Text(@"苹果健康")])
        {
            AppleHealthyViewController *vc = [[AppleHealthyViewController alloc] init];
            CustomTabBar *tabBar = (CustomTabBar *)self.tabBarController;
            [tabBar hiddenTheTabBarView];
            [self.navigationController pushViewController:vc animated:YES];
        }
        if ([title isEqualToString:SN_Text(@"意见反馈1")])
        {
            FeedBackViewController *feedVC = [[FeedBackViewController alloc]init];
            [self.navigationController pushViewController:feedVC animated:YES];
        }
        if ([title isEqualToString:SN_Text(@"Strava")]) {
            [SN_PublicClass cleanCacheAndCookie];
            SNStravaVc *vc = [[SNStravaVc alloc] init];
            CustomTabBar *tabBar = (CustomTabBar *)self.tabBarController;
            [tabBar hiddenTheTabBarView];
            [self.navigationController pushViewController:vc animated:YES];
        }
        
        if ([title isEqualToString:SN_Text(@"关联天猫精灵")]) {
            AssociatedTmallGenieViewController *vc = [[AssociatedTmallGenieViewController alloc] initWithNibName:NSStringFromClass([AssociatedTmallGenieViewController class]) bundle:nil];
            CustomTabBar *tabBar = (CustomTabBar *)self.tabBarController;
            [tabBar hiddenTheTabBarView];
            [self.navigationController pushViewController:vc animated:YES];
        }
        
        self.selected = NO;
    }
}

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
    if (buttonIndex == 1) {
        //清楚当前设备信息
        SN_USER.access_token      = @"";
        SN_USER.user_id           = @"";
        SN_PublicClass.todaySport = nil;
        SN_PublicClass.todaySleep = nil;
        SN_PublicClass.todayHeart = nil;
        SN_PublicClass.todayOx    = nil;
        SN_PublicClass.todayBp    = nil;
        SN_PublicClass.yesSport   = nil;
        SN_PublicClass.yesSleep   = nil;
        SN_PublicClass.yesHeart   = nil;
        SN_PublicClass.yesOx      = nil;
        SN_PublicClass.yesBp      = nil;
        SN_PublicClass.todayFood  = nil;
        [KK_BLEConfig updateService:0];
        [KK_BLELastDevice setObjectValue:@""];
        [KK_BLELastDeviceMac setObjectValue:@""];
        [KK_BLEConnect initiativeDismiss];
        [HASLOGIN setBOOLValue:NO];
        [kK_App enterLoginVc];
        [SN_USER updateToDB];
        [UIApplication sharedApplication].applicationIconBadgeNumber = 0;
        [@"stravaToken" setObjectValue:nil];
    }
}

- (void)shareBtnClick {
    UIGraphicsBeginImageContext(CGSizeMake(screenWidth, screenHeight));
    
    [[UIApplication sharedApplication].delegate.window.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    NSMutableArray *items = [[NSMutableArray alloc] init];
    [items addObject:image];
    
    UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:items applicationActivities:nil];
    NSMutableArray           *excludedActivityTypes  = [NSMutableArray arrayWithArray:@[
                                                                                        UIActivityTypeMessage, UIActivityTypeMail, UIActivityTypePrint, UIActivityTypeCopyToPasteboard, UIActivityTypeAssignToContact, UIActivityTypeSaveToCameraRoll, UIActivityTypeAddToReadingList, UIActivityTypePostToFlickr, UIActivityTypePostToVimeo, UIActivityTypePostToTencentWeibo, UIActivityTypeAirDrop,
                                                                                        UIActivityTypeOpenInIBooks]];
    activityViewController.excludedActivityTypes = excludedActivityTypes;
    
    [self presentViewController:activityViewController animated:YES completion:nil];
    activityViewController.completionWithItemsHandler = ^(UIActivityType __nullable activityType, BOOL completed, NSArray *__nullable returnedItems, NSError *__nullable activityError){
    };
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

@end

